#include "BasicMessageTest.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>

BasicMessageTest::BasicMessageTest(QWidget *parent) : ElaWidget(parent)
{
    setupUI();
}

void BasicMessageTest::setupUI()
{
    // 创建按钮
    m_successBtn = new ElaMessageButton("成功提示", this);
    m_errorBtn = new ElaMessageButton("错误提示", this);
    m_warningBtn = new ElaMessageButton("警告提示", this);
    m_infoBtn = new ElaMessageButton("信息提示", this);

    // 设置成功按钮
    m_successBtn->setBarTitle("操作成功");
    m_successBtn->setBarText("您的数据已成功保存到数据库");
    m_successBtn->setMessageMode(ElaMessageBarType::Success);
    m_successBtn->setDisplayMsec(3000);
    m_successBtn->setPositionPolicy(ElaMessageBarType::TopRight);

    // 设置错误按钮
    m_errorBtn->setBarTitle("操作失败");
    m_errorBtn->setBarText("网络连接超时，请检查网络设置");
    m_errorBtn->setMessageMode(ElaMessageBarType::Error);
    m_errorBtn->setDisplayMsec(5000);
    m_errorBtn->setPositionPolicy(ElaMessageBarType::Top);

    // 设置警告按钮
    m_warningBtn->setBarTitle("警告");
    m_warningBtn->setBarText("磁盘空间不足，请及时清理");
    m_warningBtn->setMessageMode(ElaMessageBarType::Warning);
    m_warningBtn->setDisplayMsec(4000);
    m_warningBtn->setPositionPolicy(ElaMessageBarType::BottomRight);

    // 设置信息按钮
    m_infoBtn->setBarTitle("系统通知");
    m_infoBtn->setBarText("新版本 v2.1.0 已发布，点击查看详情");
    m_infoBtn->setMessageMode(ElaMessageBarType::Information);
    m_infoBtn->setDisplayMsec(3500);
    m_infoBtn->setPositionPolicy(ElaMessageBarType::BottomLeft);

    // 连接信号
    connect(m_successBtn, &ElaMessageButton::clicked, this, &BasicMessageTest::onSuccessClicked);
    connect(m_errorBtn, &ElaMessageButton::clicked, this, &BasicMessageTest::onErrorClicked);
    connect(m_warningBtn, &ElaMessageButton::clicked, this, &BasicMessageTest::onWarningClicked);
    connect(m_infoBtn, &ElaMessageButton::clicked, this, &BasicMessageTest::onInfoClicked);

    // 布局
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    QLabel *titleLabel = new QLabel("消息按钮示例", this);
    titleLabel->setAlignment(Qt::AlignCenter);

    QHBoxLayout *btnLayout1 = new QHBoxLayout();
    btnLayout1->addWidget(m_successBtn);
    btnLayout1->addWidget(m_errorBtn);

    QHBoxLayout *btnLayout2 = new QHBoxLayout();
    btnLayout2->addWidget(m_warningBtn);
    btnLayout2->addWidget(m_infoBtn);

    mainLayout->addWidget(titleLabel);
    mainLayout->addLayout(btnLayout1);
    mainLayout->addLayout(btnLayout2);
    mainLayout->addStretch();
}

void BasicMessageTest::onSuccessClicked()
{
    qDebug() << "成功按钮被点击";
}

void BasicMessageTest::onErrorClicked()
{
    qDebug() << "错误按钮被点击";
}

void BasicMessageTest::onWarningClicked()
{
    qDebug() << "警告按钮被点击";
}

void BasicMessageTest::onInfoClicked()
{
    qDebug() << "信息按钮被点击";
}